package com.loto.insurance.mis.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.loto.insurance.mis.web.authority.INSAuthority;
import com.loto.insurance.mis.web.enumeration.MenuEnum;
import com.loto.insurance.mis.web.enumeration.InsTypeEnum;
import com.loto.insurance.mis.web.enumeration.IsActiveEnum;
import com.loto.insurance.mis.web.service.InsCompanyService;
import com.loto.insurance.mis.web.service.ProductInfoService;
import com.loto.insurance.mis.web.service.SupInfoService;

@Controller
public class ProductController {
  @Autowired
  ProductInfoService productInfoService;

  @Autowired
  SupInfoService supInfoService;

  @Autowired
  InsCompanyService insCompanyService;

  @INSAuthority(authorityMenu = MenuEnum.PRODUCT_LIST)
  @RequestMapping(value = "/product/list", method = RequestMethod.GET)
  public String orderlist(Model model) {
	model.addAttribute("subId", MenuEnum.PRODUCT_LIST.getIndex());
	model.addAttribute("insTypeList", InsTypeEnum.values());
	return "product/product_list";
  }

  @INSAuthority(authorityMenu = MenuEnum.PRODUCT_LIST)
  @RequestMapping(value = "/product/detail", method = RequestMethod.GET)
  public String orderdetail(
	  @RequestParam(value = "id", required = false, defaultValue = "0") long productId,
	  Model model) {
	model.addAttribute("statusList", IsActiveEnum.values());
	model.addAttribute("insTypeList", InsTypeEnum.values());
	model.addAttribute("companyList",
	    insCompanyService.getActiveInsCompanyList());
	model.addAttribute("supList", supInfoService.getActiveSupList());

	if (productId > 0) {
	  model.addAttribute("product",
		  productInfoService.findProductInfoById(productId));
	}
	return "product/product_detail";
  }
}
